package main

import "fmt"

type Account struct {
	AccountNo string
	Pwd       string
	Balance   float64
}

// 方法
func (account *Account) Save(money float64, pwd string) {
	if pwd != account.Pwd {
		fmt.Println("密码错误")
	}
	if money <= 0 {
		fmt.Println("输入金额错误")
		return
	}
	account.Balance = account.Balance + money
	fmt.Println("存款成功")
}

func (account *Account) WithMoney(money float64, pwd string) {
	if pwd != account.Pwd {
		fmt.Println("密码错误")
		return
	}
	if money <= 0 || money > account.Balance {
		fmt.Println("输入金额错误")
		return
	}
	account.Balance = account.Balance - money
}

func (account *Account) Query(pwd string) {
	if pwd != account.Pwd {
		fmt.Println("密码错误")
		return
	}
	fmt.Println("账户余额为", account.Balance)
}

func main() {
	acc1 := Account{
		AccountNo: "ICBC",
		Pwd:       "123123",
		Balance:   1000.0,
	}
	acc1.Query("123123")
	acc1.Save(2000, "123123")
	acc1.Query("123123")
	acc1.WithMoney(500, "123123")
	acc1.Query("123123")
}
